package com.ltkj.shop.controller.mobile;

import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.utils.SecurityUtils;
import com.ltkj.shop.domain.ShopReceiveAddress;
import com.ltkj.shop.service.IShopReceiveAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收货地址移动端Controller
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Api(tags = "收货地址移动端接口")
@RestController
@RequestMapping("/mobile/receiveAddress")
public class ShopReceiveAddressMobileController extends BaseController
{
    @Autowired
    private IShopReceiveAddressService shopReceiveAddressService;

    /**
     * 查询个人收货地址列表
     */
    @ApiOperation("查询个人收货地址列表")
    @GetMapping("/listBySelf")
    public TableDataInfo listBySelf(ShopReceiveAddress shopReceiveAddress)
    {
        startPage();
        shopReceiveAddress.setUserId(SecurityUtils.getLoginUser().getUserid());
        List<ShopReceiveAddress> list = shopReceiveAddressService.selectShopReceiveAddressList(shopReceiveAddress);
        return getDataTable(list);
    }

    /**
     * 获取收货地址详细信息
     */
    @ApiOperation("获取收货地址详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopReceiveAddressService.selectShopReceiveAddressById(id));
    }

    /**
     * 新增收货地址
     */
    @ApiOperation("新增收货地址")
    @Log(title = "收货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopReceiveAddress shopReceiveAddress)
    {
        return toAjax(shopReceiveAddressService.insertShopReceiveAddress(shopReceiveAddress));
    }

    /**
     * 修改收货地址
     */
    @ApiOperation("修改收货地址")
    @Log(title = "收货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopReceiveAddress shopReceiveAddress)
    {
        return toAjax(shopReceiveAddressService.updateShopReceiveAddress(shopReceiveAddress));
    }

    /**
     * 删除收货地址
     */
    @ApiOperation("删除收货地址")
    @Log(title = "收货地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopReceiveAddressService.deleteShopReceiveAddressByIds(ids));
    }
}
